---
title: 'clearCookies | Cypress Documentation'
description: Clear browser cookies for a domain in Cypress.
sidebar_label: clearCookies
---

<ProductHeading product="app" />

# clearCookies

Clear browser cookies for a domain.

:::caution

Cypress automatically clears all cookies _before_ each test to prevent state
from being shared across tests when
[test isolation](/app/core-concepts/writing-and-organizing-tests#Test-Isolation)
is enabled. You shouldn't need to use this command unless you're using it to
clear specific cookies inside a single test or test isolation is disabled.

:::

## Syntax

```javascript
cy.clearCookies()
cy.clearCookies(options)
```

### Usage

<Icon name="check-circle" color="green" /> **Correct Usage**

```javascript
cy.clearCookies() // Clear cookies for the currrent domain
```

### Arguments

<Icon name="angle-right" /> **options _(Object)_**

Pass in an options object to change the default behavior of `cy.clearCookies()`.

| Option    | Default                                                     | Description                                                                         |
| --------- | ----------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| `domain`  | Hostname of the current URL                                 | Clears the cookies from the specified domain                                        |
| `log`     | `true`                                                      | Displays the command in the [Command log](/app/core-concepts/open-mode#Command-Log) |
| `timeout` | [`responseTimeout`](/app/references/configuration#Timeouts) | Time to wait for `cy.clearCookies()` to resolve before [timing out](#Timeouts)      |

<HeaderYields />

- `cy.clearCookies()` yields `null`.

## Examples

### No Args

#### Clear cookies after logging in <E2EOnlyBadge />

In this example, on first login our server sends us back a session cookie. After
invoking `cy.clearCookies()` this clears the session cookie, and upon navigating
to an unauthorized page, our server should have redirected us back to login.

```javascript
// assume we just logged in
cy.contains('Login').click()
cy.url().should('include', 'profile')
cy.clearCookies()
cy.visit('/dashboard') // we should be redirected back to login
cy.url().should('include', 'login')
```

## Rules

<HeaderRequirements />

- `cy.clearCookies()` requires being chained off of `cy`.

<HeaderAssertions />

- `cy.clearCookies()` cannot have any assertions chained.

<HeaderTimeouts />

- `cy.clearCookies()` should never time out.

:::caution

Because `cy.clearCookies()` is asynchronous it is technically possible for there
to be a timeout while talking to the internal Cypress automation APIs. But for
practical purposes it should never happen.

:::

## Command Log

**_Clear cookies after getting cookies_**

```javascript
cy.getCookies().should('have.length', 1)
cy.clearCookies()
cy.getCookies().should('be.empty')
```

The commands above will display in the Command Log as:

<DocsImage
  src="/img/api/clearcookies/clear-all-cookies-in-cypress-tests.png"
  alt="Command Log"
/>

When clicking on `clearCookies` within the command log, the console outputs the
following:

<DocsImage
  src="/img/api/clearcookies/inspect-cleared-cookies-in-console.png"
  alt="Console Log"
/>

## See also

- [`cy.clearCookie()`](/api/commands/clearcookie)
- [`cy.getCookie()`](/api/commands/getcookie)
- [`cy.getCookies()`](/api/commands/getcookies)
- [`cy.setCookie()`](/api/commands/setcookie)
- [`Cypress.Cookies.debug()`](/api/cypress-api/cookies)
